package easy;

public class Solution_917 {
    public String reverseOnlyLetters(String s) {
        char[] chars = s.toCharArray();
        for (int i = 0, j = chars.length - 1; i < j; ) {
            char b = chars[i];
            if (b < 65 || (90 < b && b < 97) || b > 122) {
                i++;
                continue;
            }
            char e = chars[j];
            if (e < 65 || (90 < e && e < 97) || e > 122) {
                j--;
                continue;
            }
            char c = b;
            chars[i] = e;
            chars[j] = c;
            i++;
            j--;
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        Solution_917 model = new Solution_917();
        System.out.println(model.reverseOnlyLetters("ab-cd"));
        System.out.println(model.reverseOnlyLetters("a-bC-dEf-ghIj"));
        System.out.println(model.reverseOnlyLetters("Test1ng-Leet=code-Q!"));
        System.out.println('a' - 0);
        System.out.println('z' - 0);
        System.out.println('A' - 0);
        System.out.println('Z' - 0);
    }
}
